<?php
	
	$_userid = $_userid == 1 && $userid  ? $userid : $_userid; // 管理员编辑其他会员信息权限
	
	//if(!isset($action)) $action = 'manage';
	require_once 'form.class.php';
	require_once 'includes/yellowpage.class.php';
	$yellowpage = new yellowpage();
	$yellowpage->set_model('job');
	foreach($MODEL AS $modelid=>$value)
	{
		if($value['modeltype']==9 && $value['tablename'] == 'job') break;
	}
	$yellowpage->modelid = $modelid;
	
	$types = subtype('yellowpage');
	$genre = $genre ? $genre : 0;
	$inputtime = $inputtime ? $inputtime : 0;

	
	switch($action){
		   
		
		/*职位搜索*/
		case 'search':
			if($dosubmit){
				$head['keywords'] .= '职位搜索结果';
				$head['description'] .= '职位搜索结果'.'_'.$SETTING['sitename'];
				$head['title'] .= '职位搜索结果'.'_'.$SETTING['sitename'];
				if($page<1)$page = 1;
				
				require_once 'includes/job.class.php';
				$job = new job();
				$rs = $job->search_job_result($q,$inputtime,$degree,$station,$workplace,$experience,$page);
				$pages = pages($rs['number'],$page,15);
				
				include template('job_searchlist.html','yellowpage');
			}
			else{
				$head['keywords'] .= '职位搜索';
				$head['description'] .= '职位搜索'.'_'.$SETTING['sitename'];
				$head['title'] .= '职位搜索'.'_'.$SETTING['sitename'];
				include template('job_search.html','yellowpage');
			}
		break;
			
		
		case 'show': 
			$jobid = intval($id);
			require_once 'includes/yellowpage.class.php';
			require_once 'includes/company.class.php';
			$company = new company();
			//$yp = new yellowpage();
			//$yp->set_model('job');
			$rs = $yellowpage->get($jobid);
			$head['keywords'] .= $rs['keywords'].'_人才招聘';
			$head['description'] .= $rs['title'].'_人才招聘'.'_'.$SETTING['sitename'];
			$head['title'] .= $rs['title'].'_人才招聘'.'_'.$SETTING['sitename'];
			if(!$rs || $rs['status'] != '99')showmessage('数据未通过审核或者已经被删除');
			$c = $company->get($rs['userid']);
			include template('job_show.html','yellowpage');
		break;
		
	
		
		case 'add':
		if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
	
		if($dosubmit)
		{
			if(!$info['station']) showmessage('请选择岗位','goback');
			/*if(in_array($_groupid,$M['add_check']))
			{
				$info['status'] = 99;
			}
			else
			{
				$info['status'] = 1;
			}*/
			$info['status'] = 99;
			require_once MOD_ROOT.'attachment/attachment.class.php';
			$attachment = new attachment($module, $info['catid']);
			$contentid = $yellowpage->add($info);
			
			// by aming 
			//$url = "?module=$module&action=web&userid=$_userid&category=job&id=$contentid";
			//$db->query("UPDATE `".DB_PRE."yellowpage_job` SET `url`='$url' WHERE `id`=$contentid");
			showmessage('发布成功！', url("?module=$module&file=$file&action=$action&userid=$_userid"));
	
		}
		else
		{
			if($M['ischeck'] && $company_user_infos['status'] == 0) showmessage('您的公司正在审核当中...','goback');
			if($company_user_infos['endtime'] && $company_user_infos['endtime']<TIME) showmessage('您的服务截至日期已到，请续费...','goback');
			foreach($MODEL AS $modelid=>$value)
			{
				if($value['modeltype']==9 && $value['tablename'] == 'job') break;
			}
			require CACHE_MODEL_PATH.'yp_form.class.php';
			$content_form = new content_form($modelid);
			$data['catid'] = $catid;
			$forminfos = $content_form->get($data);
		}
		include template('job_add.html','yellowpage');
	break;
	
	case 'manage':
		if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
	
		$infos = $yellowpage->listinfo(/*"userid='$userid'"*/1,'id DESC',$page);
		$pages = $yellowpage->pages;
		include template('job_manage.html','yellowpage');
	break;

	case 'edit':
		if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));

		$id = intval($id);
		if($dosubmit)
		{
			require_once MOD_ROOT.'attachment/attachment.class.php';
			$attachment = new attachment($module);
			$yellowpage->edit($id, $info);
			
			// by aming 
			//$url = "?module=$module&action=web&userid=$_userid&category=job&id=$id";
			//$db->query("UPDATE `".DB_PRE."yellowpage_job` SET `url`='$url' WHERE `id`=$id");
			showmessage('修改成功！', $forward);
		}
		else
		{
			require CACHE_MODEL_PATH.'yp_form.class.php';
			$content_form = new content_form($modelid);
			$data = $yellowpage->get($id);
			$forminfos = $content_form->get($data);
		}
		include template('job_edit.html','yellowpage');
		break;
		
	case 'delete':
		if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
		
		$id = intval($id);
		$yellowpage->delete($id);
		showmessage('删除成功！', "goback");
		include template('job_manage.html','yellowpage');
		break;
		
		default:
			/*$head['keywords'] .= '人才招聘';
			$head['description'] .= '人才招聘'.'_'.$SETTING['sitename'];
			$head['title'] .= '人才招聘'.'_'.$SETTING['sitename'];
			include template('job.html','yellowpage');*/
			
			$catid = intval($catid);
			$head['keywords'] .= '职位列表';
			$head['title'] .= '职位列表'.'_'.$SETTING['sitename'];
			$head['description'] .= '职位列表'.'_'.$SETTING['sitename'];
			if($inputtime)
			$time = time() - 3600*$inputtime*24;
			else $time = 0;
			if($time < 0 )$time = 0;
			$where = "j.updatetime >= '{$time}' ";
			$genre = urldecode($genre);
			$genre = str_replace(array('(', '$', ')', '{', '}', '<', '>'), '', $genre);
			if($station)$where .= "AND j.station = '{$station}' ";
			if($genre)$where .= "AND c.genre = '{$genre}' ";
			if(!trim($where))$where = '1';
			include template('job.html','yellowpage');
		break;
	}
?>